#ifndef _CMD_H_
#define _CMD_H_

#include "util/SearchTree.h"

class CCmdList
{
public:
	static const int FLAG_PLUS = 0x01;
	static const int FLAG_MINUS = 0x02;
	class Parser
	{
	private:
		char* m_text;
		int m_pos;

		void SkipWhitespace();
	public:
		Parser(char* text);
		bool GetToken(char* text, int maxLen);
		bool GetNumber(float& val);
		bool EndCmd();
		void SkipEnd();
	};

private:
	typedef bool (*TCmdFunc)(int flags, Parser* parser);
	CSearchTree m_commands;

	bool Exec(Parser* parser);
public:
	typedef struct
	{
		char* name;
		TCmdFunc func;
	}TCmdStruct;

public:
	CCmdList();
	~CCmdList();

	bool AddCmd(char* name, TCmdFunc func);
	bool AddCmdList(TCmdStruct* list);
	bool AddAlias(char* name, char* alias);

	bool Exec(char* text);

	bool IsValidName(char* name);
};

#endif //_CMD_H_